// models/session_model.go
package models

import (
	"github.com/sirupsen/logrus"
	"gorm.io/gorm"
)

type SessionModel struct {
	//整个大会话的全部内容
	Model
	UserID    uint        `json:"userID"`
	UserModel UserModel   `gorm:"foreignKey:UserID" json:"-"`
	RoleID    uint        `json:"roleID"`
	RoleModel AiRoleModel `gorm:"foreignKey:RoleID" json:"-"`
	Title     string      `gorm:"size64" json:"title"` // 会话名称
	ChatList  []ChatModel `gorm:"foreignKey:SessionID" json:"-"`
}

func (s *SessionModel) BeforeDelete(tx *gorm.DB) error {
	logrus.Infof("删除会话 %s  会话id：%d", s.Title, s.ID)

	// 对话表
	var chatList []ChatModel
	tx.Delete(&chatList, "session_id = ?", s.ID)
	logrus.Infof("删除对话记录 %d 条", len(chatList))

	return nil
}
